﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.fmtx.Model;
using com.fmtx.IDal;
using fmtx.Framework.DALFactory;
using System.Collections;

namespace website.Areas.Action.Controllers
{
    public class AreaController : BaseController
    {
        //
        // GET: /Action/Area/
        ICity city = DataAccess<ICity>.GetObject();
        IPlace place = DataAccess<IPlace>.GetObject();

        /// <summary>
        /// 获取关键字相关的城市名称
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [OutputCache(Duration=24*60*2)]
        public ActionResult CityBykey(string keyword)
        {
            var list= city.QueryByName(keyword, 10);
            List<Hashtable> hlist = new List<Hashtable>();
            foreach (var item in list)
            {
                Hashtable hash = new Hashtable();
                hash["Id"] = item.Id;
                hash["Name"] = item.Name;
                hlist.Add(hash);
            }
            return Json(hlist, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 获取关键字相关的景点名称
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [OutputCache(Duration = 24 * 60 * 2)]
        public ActionResult PlaceBykey(string keyword,int cityid)
        {
            var list = place.QueryByName(keyword,cityid, 10);
            List<Hashtable> hlist = new List<Hashtable>();
            foreach (var item in list)
            {
                Hashtable hash = new Hashtable();
                hash["Id"] = item.Id;
                hash["Name"] = item.Name;
                hlist.Add(hash);
            }
            return Json(hlist, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 景点id获取城市名称及id
        /// </summary>
        /// <param name="placeid"></param>
        /// <returns></returns>
        [OutputCache(Duration=24*60*3)]
        public ActionResult GetCityByPlace(int placeid)
        {
            var bean = place.Get(placeid);
            return Json(new { CityName = bean.CityName, CityId = bean.CityId }, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Uparea()
        {
            place.QueryIdAndName();
            return null;
        }

    }
}
